﻿using System.ComponentModel;
using System.Runtime.Serialization;
using System.Windows;
using System.Xml.Linq;

namespace XamlaApp.ViewModels
{
    /// <summary>
    /// Provides a base from which all Xamla view models derive.
    /// Can support INotifyPropertyChanged properties or Dependency properties for databinding.
    /// </summary>
    [DataContract]
    public abstract class BaseViewModel : INotifyPropertyChanged
    {

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        protected void PropertyChanging(string property)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(property));
        }

        #endregion

        /// <summary>
        /// Allows View Model to perform any pre-processing prior to serialization.
        /// This is handy for complex or non-serializable types that require some form of special handling
        /// </summary>
        internal virtual void PreSerializeActions()
        {

        }

        /// <summary>
        /// Allows View Model to perform any post deserialization tasks.
        ///         /// This is handy for complex or non-serializable types that require some form of special handling
        /// </summary>
        internal virtual void PostDeserializeActions()
        {
            
        }

        internal virtual XElement GenerateXaml(XElement element)
        {
            return element;
        }
    }
}
